<?php
        
        require_once 'config.php';
        
        /* 插入书评
         *  */
        function addReview($title,$content,$bookId,$uId,$labelId){
            $sqlAdd="INSERT INTO Review(reviewId,title,content,good,reviewtime,bookId,uId,labelId)
                 VALUES ('','$title','$content','0',now(),'$bookId','$uId','$labelId')";
            $result=add($sqlAdd);
            return $result;
        }
        
        /* 根据reviewID查找帖子信息
         * @param reviewId
         * @review array
         * @autor huangchuting 2020.6.4
         *  */
        function getReviewId($reviewId){
            $sqlGet="SELECT * FROM Review WHERE reviewId='$reviewId'";
            $result=getQuery($sqlGet);
            if (count($result)>0)
            {
                return $result[0];
            }
            return $result;
        }
        

        
        /* 根据书评编号更新书评内容和标签
         * @param reviewId content label
         * @return array
         *  */

        function updateReview($reviewId,$content,$labelId){
            $sqlUp="UPDATE Review SET content='$content',labelId='$labelId' WHERE reviewId='$reviewId' ";
            $result=update($sqlUp);
           
            return $result;
        }
        
        /* 查找用户是否点赞过书评
         * @param reviewId uId
         * @return array
         *  */
        
        function getReviewZanUId( $reviewId,$uId){
            $sqlGet="SELECT * FROM zan WHERE reviewId='$reviewId' AND uId='$uId'";
            $result=getQuery($sqlGet);
            return $result;
        }
         
        /* 添加点赞记录
         * @param reviewId uId
         * @return row
         *  */
         function addZan($reviewId, $uId){
             $sqlAdd="INSERT INTO zan(zanId,reviewId,uId)
                       VALUES('','$reviewId','$uId')";
             $result=add($sqlAdd);
             return $result;
         }
        /* 删除点赞记录
         * @param zanId
         * @return rows
         *  */
         function deleteZan($uId,$reviewId){
             $sqlDel="DELETE FROM zan WHERE uId='$uId' AND reviewId='$reviewId' ";
             $return=delete($sqlDel);
             return $return;
         }
         
         /* 点赞后，给good字段添加1
          * @param reviewId
          * @return row
          *  */
         function upGood($reviewId){
             $sqlUp="UPDATE Review SET good= good+1 WHERE reviewId='$reviewId'";
             $result=update($sqlUp);
             return $result;
         }
         
         /* 取消点赞，给good字段减1
          * @param reviewId
          * @return row
          *  */
         function downGood($reviewId){
             $sqlUp="UPDATE Review SET good= good-1 WHERE reviewId='$reviewId'";
             $result=update($sqlUp);
             return $result;
         }
         
         /* 删除书评 
          * @return row
          * */
         function deleteReview($reviewId){
             $sqlDel="DELETE FROM Review WHERE reviewId=$reviewId ";
             $result=delete($sqlDel);
             return $result;
         }
         

         

?>